package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @aothor LentDent1
 * @vision 1.0
 */

@Configuration
// 初始化配置类会在项目启动的时候就运行了，所以一般可以为一些对象实例化创建bean对象存入spring容器中
@Slf4j
public class RedisConfiguration {
    @Bean
    public RedisTemplate redisTemplate (RedisConnectionFactory redisConnectionFactory) {
        log.info ("开始创建redis模板对象...");
        RedisTemplate redisTemplate = new RedisTemplate();
        // 设置redis的连接工厂对象
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        // 设置redis key 的序列化
        redisTemplate.setKeySerializer(new StringRedisSerializer());

        return redisTemplate;
    }
}
